home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Code Resources / icl8 LDEF 2.0 / Source / LDEF Tester.c < prev    next >
C/C++ Source or Header  |  1995-11-14  |  4KB  |  169 lines

  1.  
  2. /* CODE EXAMPLE #1 */
  3. // An example illustrating the use of the List Manager
  4. // Clicking a list element causes it to be highlighted
  5. // Double-clicking a list element causes it to beep.
  6.  
  7. // Taken from THINK Reference, with modifications for my icl8 LDEF
  8. // Nov 14 95
  9.  
  10. // ---------------------------------------------------------------------------
  11.  
  12. #include "icl8 LDEF.h"
  13.  
  14. // ---------------------------------------------------------------------------
  15.  
  16. void ToolBoxInit(void);
  17.  
  18. void ToolBoxInit() {
  19.     InitGraf(&qd.thePort);
  20.     InitFonts();
  21.     InitWindows();
  22.     TEInit();
  23.     InitDialogs(nil);
  24.     InitCursor();
  25. }
  26.  
  27. // ---------------------------------------------------------------------------
  28.  
  29. enum {
  30.     kCellSize    = 56,
  31.     kIconBegin    = 128,
  32.     kIconEnd    = 134,
  33.     kNumIcons    = kIconEnd - kIconBegin + 1
  34. };
  35.  
  36. // ---------------------------------------------------------------------------
  37.  
  38. void main() {
  39.     ListHandle    myList;
  40.     WindowPtr    myWindow;
  41.     Rect        listR, dataBounds;
  42.     Point        cSize;
  43.     short        selType, j, dummy;
  44.     Str255        s;
  45.     Boolean        done;
  46.     EventRecord    theEvent;
  47.     WindowPtr    whichWindow;
  48.     long        windSize;
  49.     short        thePart;
  50.     Rect        sizeRect;
  51.     GrafPtr        oldPort;
  52.     Boolean        beep;
  53.     short        hGrow, vGrow;
  54.     long        gestInfo;
  55.     IconListData theIcon;
  56.  
  57.     ToolBoxInit();
  58.     InitCursor();
  59.  
  60.     // Color or not?
  61.     Gestalt(gestaltQuickdrawVersion, &gestInfo);
  62.     if (gestInfo > gestaltOriginalQD)
  63.         myWindow = GetNewCWindow(128, NULL, (WindowPtr)-1);
  64.     else
  65.         myWindow = GetNewWindow(128, NULL, (WindowPtr)-1);
  66.     SetPort((GrafPtr)myWindow);
  67.  
  68.     // --------------------------------------
  69.     // Setting up list stuff here
  70.     // --------------------------------------
  71.     SetRect(&dataBounds, 0, 0, 0, 0);
  72.     SetPt(&cSize, kCellSize, kCellSize);
  73.     SetRect (&listR, 0, 0, (kCellSize * 7), (kCellSize * 7));
  74.  
  75.     myList = LNew(&listR, &dataBounds, cSize, 1972,
  76.         (WindowPtr)myWindow,true, true, true, true);
  77.     HLock((Handle)myList);
  78.     cSize = (**myList).cellSize;   // Save cellSize so we can use
  79.                                     // it later to resize the cells
  80.  
  81.     // Set icon parameters here.
  82.     theIcon.iconSize = kIconBasedOnCellSize;
  83.     theIcon.frameWidth = 2;    // Used only if kSelectByFramingBW or kSelectByFramingHilite set
  84.     theIcon.drawName = true;
  85.  
  86.     dummy = LAddRow(5, 0, myList);
  87.     dummy = LAddColumn(kSelectByDarkenIcon+1, kSelectByInvertBW, myList);
  88.  
  89.     theIcon.id = kIconBegin;
  90.     for (selType = kSelectByInvertBW; selType <= kSelectByDarkenIcon; selType++) {
  91.         theIcon.selType = selType;
  92.         for (j = 0; j < 5; j++) {
  93.             SetPt(&cSize, selType, j);
  94.             LAddToCell(&theIcon, sizeof(IconListData), cSize, myList);
  95.             LDraw(cSize, myList);
  96.             if (theIcon.id < kIconEnd)
  97.                 theIcon.id++;
  98.             else
  99.                 theIcon.id = kIconBegin;
  100.         }
  101.     }
  102.  
  103.     // --------------------------
  104.     // Event loop
  105.     // --------------------------
  106.     done = false;
  107.     SetRect (&sizeRect, 50, 50,
  108.                     qd.screenBits.bounds.bottom - qd.screenBits.bounds.top,
  109.                     qd.screenBits.bounds.right - qd.screenBits.bounds.left);
  110.  
  111.     done = FALSE;
  112.     while (!done)
  113.         if (WaitNextEvent(everyEvent, &theEvent, 30, nil )) {
  114.             switch (theEvent.what) {
  115.                 case mouseDown:
  116.                     thePart = FindWindow (theEvent.where,
  117.                             &whichWindow);
  118.  
  119.                     switch (thePart) {
  120.                         case inContent:
  121.                             GlobalToLocal(&theEvent.where);
  122.                             beep = LClick(theEvent.where,
  123.                                     theEvent.modifiers, myList);
  124.                             if (beep)
  125.                                     SysBeep (10);
  126.                         break;
  127.  
  128.                         case inGrow:
  129.                             windSize = GrowWindow (whichWindow,
  130.                                 theEvent.where, &sizeRect);
  131.                             if (windSize) {
  132.                                 GetPort (&oldPort);
  133.                                 SetPort (whichWindow);
  134.                                 hGrow = (LoWord(windSize) / kCellSize) * kCellSize + 15;
  135.                                 vGrow = (HiWord(windSize) / kCellSize) * kCellSize + 15;
  136.                                 SizeWindow (whichWindow, hGrow, vGrow, true);
  137.                                 LSize (whichWindow->portRect.right - 15,
  138.                                         whichWindow->portRect.bottom - 15, myList);
  139.                                 SetPt(&cSize, kCellSize, kCellSize);
  140.                                 DrawGrowIcon((GrafPtr)myWindow);
  141.                                 InvalRect (&whichWindow->portRect);
  142.                                 SetPort (oldPort);
  143.                             }
  144.                         break;
  145.  
  146.                         case inGoAway:
  147.                             done = TRUE;
  148.                         break;
  149.                     }
  150.                 break;
  151.  
  152.                 case updateEvt:
  153.                     if ((WindowPtr) theEvent.message == myWindow) {
  154.                         BeginUpdate ((WindowPtr) theEvent.message);
  155.                         EraseRect(&myWindow->portRect);
  156.                         DrawGrowIcon ((WindowPtr) myWindow);
  157.                         LUpdate(myWindow->visRgn, myList);
  158.                         EndUpdate ((WindowPtr) theEvent.message);
  159.                     }
  160.                 break;
  161.             }
  162.         }
  163.  
  164.     HUnlock((Handle) myList);
  165.     LDispose(myList);
  166.     DisposeWindow((WindowPtr)myWindow);
  167. }
  168.  
  169.